<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .color_list{            
            display: flex;                    
        }        
        .color_list li{            
            width: 100px;            
            height: 100px;            
            list-style: none;            
            text-align: center;            
            line-height: 100px;        
        }
/* //每个li加上对应的颜色，此处省略 */
        .a{
            background-color: red;
        }
        .b{
            background-color: orange;
        }
        .c{
            background-color: yellow;
        }
        .d{
            background-color: green;
        }
        .e{
            background-color: blue;
        }
        .f{
            background-color: purple;
        }
        .box{            
            width: 600px;            
            height: 150px;            
            background-color: #cccccc;            
            line-height: 150px;            
            text-align: center;        
        }

    </style>
</head>
<body>
    <ul class="color_list">        
        <li class="a">red</li>        
        <li class="b">orange</li>        
        <li class="c">yellow</li>        
        <li class="d">green</li>        
        <li class="e">blue</li>        
        <li class="f">purple</li>    
    </ul>
    <div class="box">box</div>

    <script>
        var color_list=document.querySelector(".color_list");            
        var colors=color_list.getElementsByTagName("li");            
        var box=document.querySelector(".box");            
        for(var n=0;n<colors.length;n++){                
                colors[n].addEventListener("click",function(){                    
                console.log(this.innerHTML)                    
                box.innerHTML="该颜色为 "+this.innerHTML;                
            })            
        }

        // function colorChange(e){                
        //     var e=e||window.event;//兼容性的处理         
        //         if(e.target.nodeName.toLowerCase()==="li"){                    
        //             box.innerHTML="该颜色为 "+e.target.innerHTML; 
        //             console.log('该颜色为：'+e.target.innerHTML);               
        //         }                            
        // }            
        // color_list.addEventListener("click",colorChange,false)
    </script>
</body>
</html>